// pages/my/electronSign/signManage/signDetail.js
var util = require('../../../../utils/util.js');
var app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    signManState: true,
    signManStateText: '展开',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this;
    wx.getStorage({
      key: 'userInfo',
      success: function(res) {
        that.setData({
          userInfo: res.data,
          file_id: options.file_id,
          sign_id: options.sign_id
        });
        that.dataLoad();
      },
      fail: function() {
        wx.redirectTo({
          url: '/pages/index/index',
        })
      }
    });
  },

  /**
   * 初始化数据
   */
  dataLoad: function() {
    wx.showLoading({
      title: '加载中···',
    });
    var that = this;
    util.getReq('/app/sign/getSignDetail', {
      file_id: that.data.file_id,
      sign_id: that.data.sign_id
    }, function(data) {
      if (data.code == 0) {
        var params = data.params;
        var sign = params.sign;
        that.setData({
          sign: sign,
          sign_time: util.format(sign.sign_time, 'yyyy-MM-dd HH:mm:ss'),
          list: params.signList
        });
      } else {
        util.isError(data.desc);
      }
      wx.hideLoading();
    });
  },

  /**
   * 查看签署方
   * 
   */
  seeSignMan: function() {
    var that = this;
    var signManState = that.data.signManState;
    if (signManState) {
      that.setData({
        signManState: false,
        signManStateText: '隐藏'
      });
    } else {
      that.setData({
        signManState: true,
        signManStateText: '展开'
      });
    }
  },

  startSign: function() {
    var that = this;
    wx.navigateTo({
      url: '/pages/my/electronSign/signManage/sign?id=' + that.data.sign_id,
    })
  },

  /**
   * 合同预览
   */
  openFile: function(e) {
    var src = e.target.dataset.src;
    wx.navigateTo({
      url: '/pages/my/electronSign/previewPdf?pdfUrl=' + encodeURIComponent(src)
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {
    this.dataLoad();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})